package com.github.yealove.configgen.dto;

import lombok.Data;

@Data
public class R<T> {

    /**
     * 结果码: 0成功, 其他失败
     */
    private int code;
    /**
     * 结果说明
     */
    private String message;
    /**
     * 结果值
     */
    private T data;

    public static R success() {
        return new R(0, "success");
    }

    public static <T> R<T> success(T data) {
        return new R(0, "success", data);
    }

    public static R fail(int code, String message) {
        return new R(code, message);
    }

    public static <T> R<T> fail(int code, String message, T data) {
        return new R(code, message, data);
    }

    public R(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public R(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
